#include<bits/stdc++.h>
using namespace std;
const int N=1010,mod=1e9+7;
int n,a[N],b[N];
map<string,bool>s;
inline void upd(int &x,int y) {x+=y;x=(x>=mod)?x-mod:x;}
void dfs(int x,int y,string S)
{
    if(x==n&&y==n)
        return s[S]=1,void();
    if(x<n) dfs(x+1,y,S+(char)(b[y]^48));
    if(y<n) dfs(x,y+1,S+(char)(a[x]^48));
}
int main()
{
    freopen("zha.in","r",stdin);
    freopen("zha.out","w",stdout);
    scanf("%d",&n);
    for(int i=1;i<=n;i++) scanf("%d",a+i),--a[i];
    for(int i=1;i<=n;i++) scanf("%d",b+i),--b[i];
    dfs(1,1,"");
    printf("%d\n",(int)s.size());
    return 0;
}